﻿// <copyright file="NumericFormatConverter.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-03</date>
// <summary>Numeric Format Converter</summary>

namespace NYTimesSilverlightLibrary
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    /// <summary>
    /// Numeric format converter
    /// </summary>
    public class NumericFormatConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <summary>
        /// convert a double to a string with the parameter as the format and culture
        /// </summary>
        /// <param name="value">a double value</param>
        /// <param name="targetType">the string type</param>
        /// <param name="parameter">the string format</param>
        /// <param name="culture">the conversion culture</param>
        /// <returns>a formatted string</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string format = (string)parameter;

            if (value is double)
            {
                double number = (double)value;

                return number.ToString(format, culture);
            }
            else if (value is int)
            {
                int number = (int)value;

                return number.ToString(format, culture);
            }

            return null;
        }

        /// <summary>
        ///  Not implemented
        /// </summary>
        /// <param name="value">The parameter is not used.</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>not implemented</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
